<template>
    <!-- 传统dao模型 -->
    <dao :sid="sid" />

</template>

<script setup>
import { useRouter, useRoute } from 'vue-router';
import { ref, watch } from 'vue';
import dao from "@/components/dao"
import { useModelStore } from '@/stores/model';



import { getModelByMid } from '@/api/model';

const router = useRouter();
const route = useRoute();

const mid = ref()
const sid = ref(0)

const modelInfo = ref({
    id: 0,
    serverUrl: '',
    modelName: '',
    intro: '',
    avatar: '',
    servedModelName: ''
})

const modelStore = useModelStore()



// 为组件参数赋值，监听路由参数变化，分为从菜单进入与从所有会话页面进入
watch([() => route.params.modelName, () => route.params.sid, () => route.query.mid, () => route.query.modelIntro, () => route.query.servedModelName], ([newModelName, newSid, newMid, newModelIntro, newServedModelName], [oldModelName, oldSid, oldMid, oldModelIntro, oldServedModelName]) => {
    // mid无论从哪个页面进入都携带，所以直接赋值
    // mid.value = route.query.mid
    // 从所有会话页面进入时，需要根据mid获取模型信息，因为从所有会话页面进入只携带mid，没有其他参数
    if (router.currentRoute.value.path.includes('/session')) {
        sid.value = route.params.sid
        //更改一下，从菜单进入将模型信息直接存入store不再从路由获取
        mid.value = route.query.mid
        getModelByMid({
            id: mid.value
        }).then(res => {
            // console.log(res.data);
            modelStore.setModelInfo(res.data)
        })
    }
    // 从菜单进入时，直接赋值
    else {
        sid.value = 0
    }

}, { immediate: true });



</script>

<style lang="scss" scoped></style>